package com.boot.controller;
import java.util.ArrayList;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.boot.entity.Ctime;
import com.boot.service.CtimeService;
import com.boot.util.PageHelper;
//定义为控制器
@Controller
// 设置路径
@RequestMapping(value = "/ctime" , produces = "text/plain;charset=utf-8")
public class CtimeController extends BaseController {
	// 注入Service 由于标签的存在 所以不需要getter setter
	@Autowired
	private CtimeService ctimeService;

	// 准备添加数据
	@RequestMapping("createCtime.action")
	public String createCtime() {
		return "admin/addctime";
	}
	// 添加数据
	@RequestMapping("addCtime.action")
	public String addCtime(Ctime ctime) {
		this.ctimeService.insertCtime(ctime);
		return "redirect:/ctime/createCtime.action";
	}

	// 通过主键删除数据
	@RequestMapping("deleteCtime.action")
	public String deleteCtime(String id) {
		this.ctimeService.deleteCtime(id);
		return "redirect:/ctime/getAllCtime.action";
	}

	// 批量删除数据
	@RequestMapping("deleteCtimeByIds.action")
	public String deleteCtimeByIds() {
		String[] ids = this.getRequest().getParameterValues("ctimeid");
		for (String ctimeid : ids) {
			this.ctimeService.deleteCtime(ctimeid);
		}
		return "redirect:/ctime/getAllCtime.action";
	}

	// 更新数据
	@RequestMapping("updateCtime.action")
	public String updateCtime(Ctime ctime) {
		this.ctimeService.updateCtime(ctime);
		return "redirect:/ctime/getAllCtime.action";
	}

	// 显示全部数据
	@RequestMapping("getAllCtime.action")
	public String getAllCtime(String number) {
		List<Ctime> ctimeList = this.ctimeService.getAllCtime();
		PageHelper.getPage(ctimeList, "ctime", null, null, 10, number, this.getRequest(), null);
		return "admin/listctime";
	}

	// 按条件查询数据 (模糊查询)
	@RequestMapping("queryCtimeByCond.action")
	public String queryCtimeByCond(String cond, String name, String number) {
		Ctime ctime = new Ctime();
		if(cond != null){
			if ("ctimename".equals(cond)) {
				ctime.setCtimename(name);
			}
			if ("sectionx".equals(cond)) {
				ctime.setSectionx(name);
			}
			if ("memo".equals(cond)) {
				ctime.setMemo(name);
			}
		}

		List<String> nameList = new ArrayList<String>();
		List<String> valueList = new ArrayList<String>();
		nameList.add(cond);
		valueList.add(name);
		PageHelper.getPage(this.ctimeService.getCtimeByLike(ctime), "ctime", nameList, valueList, 10, number, this.getRequest(), "query");
		name = null;
		cond = null;
		return "admin/queryctime";
	}

	// 按主键查询数据
	@RequestMapping("getCtimeById.action")
	public String getCtimeById(String id) {
		Ctime ctime = this.ctimeService.getCtimeById(id);
		this.getRequest().setAttribute("ctime", ctime);
		return "admin/editctime";
	}

	public CtimeService getCtimeService() { return ctimeService; }

	public void setCtimeService(CtimeService ctimeService) { this.ctimeService = ctimeService; }

}
// 程序开发 QQ 709664889 可以付费修改
